package com.demoworld;

import redis.clients.jedis.Jedis;

import java.util.UUID;

/**
 * Created by li_wb on 2018/1/23.
 */
public class Main {
    public static void main(String[] args) {
//        testRedisWatch();
        mockSeckill();
    }

    public static void testRedisWatch() {
        SeckillService seckillService = new SeckillService();
        Jedis client = seckillService.getConnection();
        String key = "aasdasd";
        String value = UUID.randomUUID().toString();
        client.set(key, value);
        client.watch(key);
        delKey(key);
        client.unwatch();
        delKey(key);
        client.close();
    }

    public static void delKey(String key) {
        SeckillService seckillService = new SeckillService();
        Jedis client = null;
        try {
            client = seckillService.getConnection();
            System.out.println("删除key结果=" + client.del(key));
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            client.close();
        }
    }

    //mock 秒杀功能
    public static void mockSeckill() {
        SeckillService service = new SeckillService();
        for (int i = 0; i < 50; i++) {
            SeckillUserA threadA = new SeckillUserA(service);
            threadA.start();
        }
    }
}
